]> git.r.bdr.sh - rbdr/super-polarity/blame - Super Polarity/Widget.cs
Edits them colors
[rbdr/super-polarity] / Super Polarity / Widget.cs
CommitLineData
74c15570
BB
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace SuperPolarity
7{
8 class Widget
9 {
10 public IList<Widget> Children;
11 public Dictionary<string, List<Action<float>>> Listeners;
12
13 public virtual void AppendChild(Widget widget)
14 {
15 Children.Add(widget);
16 }
17
18 public virtual void Bind(string eventName, Action<float> eventListener)
19 {
20 List<Action<float>> newListenerList;
21 List<Action<float>> listenerList;
22 bool foundListeners;
23
24 if (!Listeners.ContainsKey(eventName))
25 {
26 newListenerList = new List<Action<float>>();
27 Listeners.Add(eventName, newListenerList);
28 }
29
30 foundListeners = Listeners.TryGetValue(eventName, out listenerList);
31
32 listenerList.Add(eventListener);
33 }
34
35 public virtual void Unbind(string eventName, Action<float> eventListener)
36 {
37 // NOT YET IMPLEMENTED;
38 }
39
40 public virtual void Dispatch(string eventName, float value)
41 {
42 List<Action<float>> listenerList;
43 bool foundListeners;
44
45 foundListeners = Listeners.TryGetValue(eventName, out listenerList);
46
47 if (!foundListeners)
48 {
49 return;
50 }
51
52 foreach (Action<float> method in listenerList)
53 {
54 method(value);
55 }
56 }
57 }
58}